//
//  ZNLetterViewController.m
//  u76ho
//
//  Created by m-air-01 on 16/1/8.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "ZNLetterViewController.h"

@interface ZNLetterViewController ()

@end

@implementation ZNLetterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self main];
    
    [self addBackItem];
    
    self.navigationItem.title = @"站内信";
   // [self addBackItem];
   // [self addNavgationBar];
    // Do any additional setup after loading the view.
}
-(void)main
{
    self.view.backgroundColor = [UIColor whiteColor];
    [self requestData];
}
-(void)requestData
{
//    {
//        0 = "\U5bf9\U4f60\U53d1\U5e03\U7684\U4fe1\U606f\U8fdb\U884c\U4e86\U70b9\U8d5e";
//        1 = 391;
//        2 = "<null>";
//        3 = 1456746179;
//        4 = "\U5feb\U4e50\U5de5\U4f5c";
//        addtime = 1456746179;
//        content = 391;
//        pic = "<null>";
//        title = "\U5bf9\U4f60\U53d1\U5e03\U7684\U4fe1\U606f\U8fdb\U884c\U4e86\U70b9\U8d5e";
//        username = "\U5feb\U4e50\U5de5\U4f5c";
//    }

    
    __weak typeof(self)weakSelf = self;
    [U76HONet zhanneiDetailWithaction:@"" idm:_ids andDataBlock:^(ZNLetterDetailModel *model) {
        NSLog(@"站内信获取数据成功了");
        
        //头像
        UIImageView * headerImgV = [[UIImageView alloc]initWithFrame:CGRectMake(SIZETO6W(15),64 + 15, 40, 40)];
        headerImgV.layer.masksToBounds = YES;
        headerImgV.layer.cornerRadius = 20;
        if (model.headpic) {
            [headerImgV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",U76HOURL,model.headpic]] placeholderImage:[UIImage imageNamed:@"公司简介成长－默认头像"]];
        }
        [weakSelf.view addSubview:headerImgV];
        //用户名
        UILabel * nameLab = [[UILabel alloc]initWithFrame:CGRectMake(headerImgV.right+SIZETO6W(10), 64 + 15, 100, 20)];
        nameLab.text = model.username;
        nameLab.font = [UIFont systemFontOfSize:15];
        nameLab.textColor = UIColorFromRGB(0x333944);
        [weakSelf.view addSubview:nameLab];
        
        
        
        UILabel * contentLab = [[UILabel alloc]initWithFrame:CGRectMake(headerImgV.right+SIZETO6W(10), nameLab.bottom, SCREEN_WIDTH - headerImgV.right-SIZETO6W(10) , 20)];
        contentLab.text = model.title;
        [weakSelf.view addSubview:contentLab];
        
        
        //时间
        UILabel * dateLab = [[UILabel alloc]initWithFrame:CGRectMake(headerImgV.right+SIZETO6W(10), contentLab.bottom, 200, 20)];

        NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        NSString * dataCh = model.addtime;
        NSString * dataStr = [dataCh substringToIndex:dataCh.length];
        NSDate * data = [[NSDate dateWithTimeIntervalSince1970:[dataStr integerValue]] dateByAddingTimeInterval:8*3600];
        NSString * lastStr = [NSString stringWithFormat:@"%@",data];
        NSArray * lastArr = [lastStr componentsSeparatedByString:@" "];
        NSMutableArray * mArr = [[NSMutableArray alloc]init];
        for (int i = 0; i<2; i++) {
            [mArr addObject:lastArr[i]];
        }
        dateLab.text = [mArr componentsJoinedByString:@" "];
        
        dateLab.font = [UIFont systemFontOfSize:15];
        dateLab.textColor = UIColorFromRGB(0x94999F);
        [weakSelf.view addSubview:dateLab];

        


    }];
}
#pragma  mark - 返回按钮图标
-(void)addBackItem{
    UIButton * backItem = [UIButton buttonWithType:UIButtonTypeCustom];
    backItem.frame = CGRectMake(0, 0, 9, 17);
    [backItem setImage:[UIImage imageNamed:@"返回图标"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItem:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backItem];
}
-(void)backItem:(id)sender
{
    if (_isAPNS) {
        AppDelegate * app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        self.view.window.rootViewController = app.viewController;
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
